โ– humdrum codex / glint v1.0.2
license AGPL-3.0
2.5 KB raw
id
TASK-006
title
Undo / redo
status
๐Ÿ Done
assignee
@humdrum
created_date
2026-06-29 16:26
updated_date
2026-06-29 19:21
labels
feature, release-1
dependencies
priority
high
ordinal
6000

Description

Release 1. The biggest gap and a data-loss safety net (select-all+type or Ctrl+U is currently unrecoverable). Add an undo stack in internal/editor capturing buffer+cursor snapshots (or reversible ops). Coalesce consecutive typing into one undo group; each structural op (newline, delete, paste, cut, delete-selection, kill-line, word-delete) is its own group. Bound history (e.g. 500 entries). Keys: Ctrl+Z undo, Ctrl+Y (and Ctrl+Shift+Z) redo. Restore cursor + scroll on undo/redo. Mark Dirty appropriately.

Acceptance Criteria

Implementation Plan

  1. editor: snapshot struct {lines,cursor,scroll,anchor}; undo/redo stacks + lastKind; maxUndo=500.
  2. HandleKey wraps dispatch: classify key -> nav (break coalesce) | kindType (coalesce) | kindStructural (own group). Snapshot pre, run, commit if content changed; cap+clear redo.
  3. Undo()/Redo() swap snapshots, restore lines/cursor/scroll/anchor, Dirty=true. SetContent resets history. PushUndo() for app-driven paste/cut.
  4. app: Ctrl+Z->Undo, Ctrl+Y->Redo; PushUndo before paste/cut. (Ctrl+Shift+Z not sendable by terminals; Ctrl+Y is redo.)
  5. TDD: tests for coalesce, structural groups, cursor/selection restore, redo-cleared-on-edit, bounded history.

Implementation Notes

Implemented snapshot-based undo/redo in internal/editor/undo.go: bounded (500) undo/redo stacks; HandleKey wraps dispatch to record a checkpoint per edit group โ€” typing coalesces, structural ops (newline/delete/kill/word-delete/paste/cut) are separate groups; no-op keys skipped. Undo/Redo restore lines+cursor+scroll+selection; SetContent clears history; PushUndo() for app paste/cut. App: Ctrl+Z undo, Ctrl+Y redo (Ctrl+Shift+Z not distinguishable by terminals). Tests: internal/editor/undo_test.go + app routing test. Help text + README updated.